

jQuery(document).ready(function() {
	
	init();
	
	initq();
	
	$("#back").click(function(){
		window.location.href="../question/index.html";
	})				
});		

function init(){
	//获取主键
	var pk=location.search.substring(1);
	pk=pk.replace('param=','');
	var da={};
	da.QUESTIONNAIREID=pk;
	da.pageNum="1";
	da.pageSize="10";
	$.ajax({ 
		type:"post",
		url: basePath() + 'question/list.do',
		data:JSON.stringify(da),
		dataType: "json",
		contentType : 'application/json;charset=UTF-8',
		success: function(data){			
			$("#pk").val(data.rows[0].QUESTIONNAIREID);
			$("#title").html(data.rows[0].QUESTIONNAIRETITLE);
			$("#disc").html(data.rows[0].QUESTIONNAIREDISC);			
      	}
	});
}

function initq() {
	//获取主键
	var pk=location.search.substring(1);
	pk=pk.replace('param=','');
	var da={};
	da.QUESTIONNAIREID=pk;
	da.pageNum="1";
	da.pageSize="10";
	$.ajax({ 
		type:"post",
		url: basePath() + 'question/qlist.do',
		data:JSON.stringify(da),
		dataType: "json",
		contentType : 'application/json;charset=UTF-8',
		success: function(data){	
			console.log(data);
			var questions = data.rows;
			var info="";
			for (var i = 0; i < questions.length; i++) {
				var question=questions[i];
				info+='<div class="form-group"><div class="col-sm-1"></div><div class="col-sm-10"><hr style="height:1px;border:none;border-top:1px solid #555555;" />';
					info+='<h4>'+question.QUESTION+'</h4>';
					var items=question.QUESTIONITEM;
					var item =items.split(",");
					var results =question.ITEMNUM;
					var result =results.split(",");
					var zong=0;
					for (var z = 0; z < result.length; z++) {
						zong +=parseInt(result[z]);
					}					
					for (var j = 0; j < item.length; j++) {	
						var fen =parseInt(result[j]);
						var jl=fen/zong*100;
						jl=jl.toFixed(2);
						info+='<div class="form-group">';
						info+='<div class="col-sm-1">'+item[j]+'</div>';
						info+='<div class="col-sm-3"><div class="progress" style="width: 300px"><span class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width:'+jl+'%;>';
						info+='<span class="sr-only">'+jl+'%</span>';
						info+='</div></div>';
						info+='<div class="col-sm-2">'+fen+'票</div>';
						info+='</div>';
					}					
			info+='</div><div class="col-sm-1"></div></div>';
			}			
		$("#info").html(info);
      	}
	});
}
